package com.zx.map.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Component;

import com.zx.map.dao.ProductDao;
import com.zx.map.dao.model.Product;
import com.zx.map.service.ProductService;
import com.zx.map.service.model.ProductModel;

@Component("productService")
public class ProductServiceImpl implements ProductService {

	@Autowired
	private ProductDao dao;
	
	/**
	 * 得到所有数据列表
	 */
	public List getAllList() throws DataAccessException {

		List<Product> list = dao.getListByExample(null);
		List<ProductModel> modelList = new ArrayList<ProductModel>();
		for (Product p : list) {
			ProductModel temp = new ProductModel();
			temp.setProductId(p.getProductId());
			temp.setProductName(p.getProductName());
			temp.setTotalProfit(new BigDecimal(p.getTotalProfit()));
			modelList.add(temp);
		}
		return modelList;

	}

	/**
	 * 根据单Key查找Model
	 */
	public ProductModel getModelByKey(long key) throws DataAccessException {
		Product p = dao.selectByPrimaryKey(key);
		ProductModel model = new ProductModel();
		if(p!=null){
			BeanUtils.copyProperties(p, model);
		}
		return model;
	}

	@Override
	public List getListByModel(ProductModel model) throws DataAccessException {
		// TODO Auto-generated method stub
		return null;
	}
}
